#include <header.h>

int getsize(char *path){
    int size = 0;
    DIR * p = opendir(path);
    while(1){
        struct dirent *pdirent = readdir(p);
        if(pdirent == NULL){
            return size;
        }
        if((pdirent->d_type == DT_REG) && (strcmp(pdirent->d_name,"1.txt") == 0)){

            char buf[300] = {0};
            sprintf(buf,"%s/%s",path,pdirent->d_name);


            struct stat st;
            stat(buf,&st);

            size += st.st_size;
        }
        if(pdirent->d_type == DT_DIR && strcmp(pdirent->d_name,".") != 0 && strcmp(pdirent->d_name,"..") != 0){

            char buf[300] = {0};
            sprintf(buf,"%s/%s",path,pdirent->d_name);
            int size2 = getsize(buf);
            size += size2;
           }
    }
    return size;
}


int main(){
    int ret = getsize("./test");
    printf("ret:%d\n",ret);
        return 0;
}

